package controllers

import (
	"blog/models"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"strconv"
)

// PortfolioController operations for Portfolio
type PortfolioController struct {
	beego.Controller
}

func (c *PortfolioController) Index() {
	idStr := c.Ctx.Input.Param(":id")
	fmt.Print(idStr)
	id, _ := strconv.ParseInt(idStr, 0, 64)
	var fields []string
	var sortby []string
	var order []string
	var query = make(map[string]string)
	var limit int64 = 10
	var offset int64

	cates, err := models.GetAllArticle_category(query, fields, sortby, order, offset, limit)
	if err != nil {
		logs.Error(err)
		c.Abort("404")
	} else {
		c.Data["Cates"] = cates
	}
	fmt.Print(cates)

	_, _, articles := models.GetArticlesByCatId(id)
	fmt.Print(articles)
	//if err != nil {
	//	c.Abort("404")
	//} else {
	//	c.Data["Cate"] = cate
	//}
	//fmt.Print(cate)

	c.Data["Title"] = "图库"
	c.Layout = "portfolio/portfolio_layout.tpl"
	c.TplName = "portfolio/portfolio_content.tpl"
	c.LayoutSections = make(map[string]string)
	c.LayoutSections["Head"] = "common/head.tpl"
	c.LayoutSections["OtherHead"] = "portfolio/portfolio_head.tpl"
	c.LayoutSections["Menu"] = "common/menu.tpl"
	c.LayoutSections["Footer"] = "common/footer.tpl"
	c.LayoutSections["Script"] = "common/script.tpl"
	c.LayoutSections["OtherScript"] = "portfolio/portfolio_script.tpl"
}
